package com.cf.game.cowboy.handler;

import com.cf.game.Player;
import com.cf.game.cowboy.CowBoyGame;
import com.cf.game.cowboy.GameStateDetail;
import com.cf.game.cowboy.MessageHandler;
import com.cf.game.cowboy.msg.CowGameInfoRequest;
import com.cf.game.cowboy.msg.CowGameInfoResponse;
import com.cf.game.service.constants.EnumH5CowBoyGameState;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * cf-game-StakeMessageHandler
 * 获取用户
 *
 * @author <a href="2428922347@qq.com">Zhu mingming</a>
 * @info
 * @since 2018/3/27 14:34
 */
@Component
public class GameInfoMessageHandler implements MessageHandler<CowGameInfoRequest, CowBoyGame> {


    @Override
    @Transactional
    public void handle(Player player, CowBoyGame game, CowGameInfoRequest message) {
        GameStateDetail gameStateDetail = game.gameStateDetail;
        CowGameInfoResponse infoResponse = gameStateDetail.toCowQueryGameInfoResponse(player.getUserInfo().getId());
        infoResponse.setCanPlay(EnumH5CowBoyGameState.STAKE.equals(game.state));
        player.unicast(infoResponse);
    }

    public boolean support(Class clazz) {
        return CowGameInfoRequest.class.equals(clazz);
    }


}
